package com.community.backend.controller;

import com.community.backend.pojo.Security;
import com.community.backend.pojo.User;
import com.community.backend.pojo.dto.SecurityQueryDTO;
import com.community.backend.service.SecurityService;
import com.community.backend.utils.PageResult;
import com.community.backend.utils.Result;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
安保
 */
@RestController
@RequestMapping("/security")
public class SecurityController {
    private final SecurityService securityService;

    public SecurityController(SecurityService securityService) {
        this.securityService = securityService;
    }

    @GetMapping("/page")
    public Result<PageResult> securityByPage(SecurityQueryDTO securityQueryDTO) {
        PageResult pageResult = securityService.securityByPage(securityQueryDTO);
        return Result.success(pageResult);
    }
    @PutMapping("/resetPwd/{id}")
    public Result resetPwd(@PathVariable String id) {
        Security security = new Security();
        security.setId(id);
        security.setPassword("123456");
        securityService.update(security);
        return Result.success();
    }

    @PutMapping
    public Result securityUpdate(@RequestBody Security security) {
         securityService.update(security);
         return Result.success("更新成功");
    }
//    //重置密码
//    @PutMapping("/resetPwd/{id}")
//    public Result resetPwd(@PathVariable Integer id) {
//        Security security = new Security();
//        security.setId(id);
//        security.setPassword("123456");
//        return securityService.updateById(security);
//    }
    @DeleteMapping("/{id}")
    public Result securityDeleteById(@PathVariable String id) {
         securityService.deleteById(id);
         return Result.success("删除成功");
    }
    @PostMapping
    public Result securityAdd(@RequestBody Security security) {
        System.out.println("添加用户信息："+ security);
         securityService.addUser(security);
         return Result.success("添加成功");
    }
}
